JavaScript: How to reverse order=[] arrays from last to first?

Posted by Binyamin on Stack Overflow See other posts from Stack Overflow or by Binyamin
Published on 2010-05-31T14:04:56Z Indexed on 2010/05/31 15:23 UTC
Read the original article Hit count: 247

Filed under:
|
|
|

My js code does POST order.php?order[]=1&order[]=2&order[]=3&order[]=4&order[]=5&&action=update How to reverse it to order.php?order[]=5&order[]=4&order[]=3&order[]=2&order[]=1&&action=update ?

JavaScript:
order=[];
//var reversed = $(this).sortable("serialize").split("&").reverse().join("&");
//var order = reversed + '&action=update'; //unfortunately it does not work so
$('#list ul').children('li').each(function(idx, elm) {
order.push(elm.id.split('-')[1])
});
$.post('order.php', {'order[]': order, action: 'update'});

HTML:
<ul>
<li id="oreder-5">5</li>
<li id="oreder-4">4</li>
<li id="oreder-3">3</li>
<li id="oreder-2">2</li>
<li id="oreder-1">1</li>
<ul>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery